package com.lzc.test.common;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
import org.springframework.core.io.Resource;

public class Constant {

	// 通过构造器注入
	private Resource constant;
	// 通过set方法注入
	private Resource constant2;
	// 与properties文件映射
	private Properties properties;

	public Constant(Resource constant) {
		super();
		this.constant = constant;
	}

	public void setConstant2(Resource constant2) {
		this.constant2 = constant2;
	}

	public void init() {
		synchronized (this) {
			try {
				properties = new Properties();
				InputStreamReader reader = new InputStreamReader(constant.getInputStream(), "UTF-8");
				InputStreamReader reader2 = new InputStreamReader(constant2.getInputStream(), "UTF-8");
				properties.load(reader);
				properties.load(reader2);
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

	}

	public String getProperties(String key) {
		return (String) properties.getProperty(key);
	}

}
